//
//  AFNetworkManager.h
//  OilUnion
//
//  Created by itte on 2016/11/10.
//  Copyright © 2016年 funmain. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
/**
 *  手机网络状态
 */
typedef enum{
    StatusUnknown           = -1,   //未知网络
    StatusNotReachable      = 0,    //没有网络
    StatusReachableViaWWAN  = 1,    //手机自带网络
    StatusReachableViaWiFi  = 2     //wifi
    
}NetworkStatus;

/**
 *  请求类型 HTTP OR HTTPS
 */
typedef enum RequestType {
    HTTP,
    HTTPS
} RequestType;

/**
 *  请求方式 GET OR POST
 */
typedef enum RequestMethod {
    GET,
    POST
} RequestMethod;

/**
 *  请求返回成功和失败回调
 */
typedef void (^RequestSuccessed)(id responseObject, NSString *errorMessage);
typedef void (^RequestFailure)(NSString *errorCode, NSString *errorMessage);


@interface AFNetworkManager : NSObject
@property (assign, nonatomic) NetworkStatus networkStatus;
/**
 *  单例
 */
+(AFNetworkManager *)sharedInstance;

/**
 *  开启网络监测
 */
- (void)startNetworkMonitor;
/**
 *  获取网络状态
 */
- (NetworkStatus)checkNetStatus;

/**
 *  post 或者 get 请求方法,block回调
 *  @param requestType      网络请求类型
 *  @param requestMethod    网络请求方法
 *  @param url              请求连接，根路径
 *  @param header           请求头
 *  @param params           参数字典
 *  @param loadingImageArr  loading图片数组
 *  @param showView         HUD 展示view
 *  @param success          请求成功返回数据
 *  @param fail             请求失败
 *  @param showHUD          是否显示HUD
 */
-(void)getOrPostWithType:(RequestType)requestType
              WithMethod:(RequestMethod)requestMethod
                 WithUrl:(NSString *)url
              withHeader:(NSString *)header
                  params:(NSDictionary *)params
         loadingImageArr:(NSMutableArray *)loadingImageArr
           toShowHUDView:(UIView *)showView
                 success:(RequestSuccessed)success
                    fail:(RequestFailure)fail
                 showHUD:(BOOL)showHUD;

/**
 *  post 或者 get 请求方法,block回调
 *  @param requestType      网络请求类型
 *  @param url              请求连接，根路径
 *  @param image            图片
 *  @param params           参数字典
 *  @param success          请求成功返回数据
 *  @param fail             请求失败
 */
-(void)uploadImageWithType:(RequestType)requestType
                   WithUrl:(NSString *)url
                 withImage:(UIImage *)image
                    params:(NSDictionary *)params
                   success:(RequestSuccessed)success
                      fail:(RequestFailure)fail;

#pragma mark - 常用的http请求
// get请求
-(void)httpGetWithUrl:(NSString *)url
               params:(NSDictionary *)params
              showHUD:(BOOL)showHUD
        toShowHUDView:(UIView *)showView
              success:(RequestSuccessed)success
                 fail:(RequestFailure)fail;
// post请求
-(void)httpPostWithUrl:(NSString *)url
                params:(NSDictionary *)params
               showHUD:(BOOL)showHUD
         toShowHUDView:(UIView *)showView
               success:(RequestSuccessed)success
                  fail:(RequestFailure)fail;

// 文件上传
-(void)httpUploadImageWithUrl:(NSString *)url
                withImage:(UIImage *)image
                   params:(NSDictionary *)params
                  success:(RequestSuccessed)success
                     fail:(RequestFailure)fail;

#pragma mark - 常用的https请求
// get请求
-(void)httpsGetWithUrl:(NSString *)url
                params:(NSDictionary *)params
               showHUD:(BOOL)showHUD
         toShowHUDView:(UIView *)showView
               success:(RequestSuccessed)success
                  fail:(RequestFailure)fail;
// post请求
-(void)httpsPostWithUrl:(NSString *)url
                 params:(NSDictionary *)params
                showHUD:(BOOL)showHUD
          toShowHUDView:(UIView *)showView
                success:(RequestSuccessed)success
                   fail:(RequestFailure)fail;

// 文件上传
-(void)httpsUploadImageWithUrl:(NSString *)url
                     withImage:(UIImage *)image
                        params:(NSDictionary *)params
                       success:(RequestSuccessed)success
                          fail:(RequestFailure)fail;
@end
